'''
python3 -- > file
coding -- > utf-8
'''
import urllib.request as ur
from re import search, findall, sub
from random import choice

url = 'http://jandan.net/duan'
text = []  # Full list
head = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26'
                      ' Safari/537.36 Core/1.63.6735.400 QQBrowser/10.2.2614.400'}


def get_all_text():
    html = ur.urlopen(ur.Request(url, headers=head)).read().decode('utf-8')  # The request page
    li = search('<ol class="commentlist"[\s\S]*?</ol>', html)[0]  # Get all the lists
    list_li = findall('<li id="comment-[\s\S]*?举报[\s\S]*?吐槽[\s\S]*?</li>', str(li))  # Get the list of sections
    for i in list_li:
        text.append(sub('(<br />)|(<br>)', '', search('<p>[\s\S]*?</p>', i)[0][3:-4]))  # Match all the pieces
    return text


def get_random_text():  # A random
    return choice(get_all_text())


if __name__ == '__main__':
    print(get_random_text())
